"use strict";
cc._RF.push(module, 'f762cpzeu1G85gIq72YX7/9', 'facebookScrollView');
// Script/facebookScrollView.js

'use strict';

var faceItem = cc.Class({
    name: 'faceItem',
    properties: {

        rankleaveimage: cc.String,
        rankName: cc.String,
        rankheadimage: cc.Integer,
        score: cc.String

    }
});
cc.Class({
    extends: cc.Component,

    properties: {
        items: {
            default: [],
            type: faceItem
        }, //代码几个item格子 初始化
        itemPrefab: cc.Prefab, //预制节点 代表cell内容详情
        myheadSprite: cc.Node,
        mynameLabel: cc.Label,
        myscoreLabel: cc.Label,
        mysignSprite: cc.Node,
        ListAllScrollView: cc.Node,
        RankingAllView: cc.Node,
        myrankLabel: cc.Label,
        rankCloseBtn: cc.Button,
        wordScrolView: cc.Node
    },

    onLoad: function onLoad() {},
    init: function init() {
        var _this2 = this;

        if (this.items.length > 0) {
            this.node.removeAllChildren();
        }

        FBInstant.getLeaderboardAsync('mouseFriend').then(function (leaderboard) {
            console.log('--leaderboard--');
            console.log(leaderboard);
            return leaderboard.getConnectedPlayerEntriesAsync(100, 0);
        }).then(function (entries) {
            console.log('--entries--');

            for (var i = 0; i < entries.length; ++i) {

                var item = cc.instantiate(_this2.itemPrefab);
                _this2.node.addChild(item);
                var items = entries[i];
                var player = items.getPlayer();
                var obj = {};
                obj["name"] = player.getName();
                obj["avatar"] = player.getPhoto();
                obj["score"] = items.getScore();
                obj["user_rank"] = i + 1;
                console.log(i);
                item.getComponent('listPrefab').init(obj);

                var playerID = FBInstant.player.getID();
                if (playerID === player.getID()) {
                    var _this = _this2;
                    console.log("头像", obj["avatar"]);
                    cc.loader.load({ url: obj["avatar"], type: 'png' }, function (err, img) {

                        var mylogo = new cc.SpriteFrame(img);

                        _this.myheadSprite.getComponent(cc.Sprite).spriteFrame = mylogo;

                        _this.myheadSprite.width = 82;

                        _this.myheadSprite.height = 82;
                    });
                    _this2.mynameLabel.getComponent(cc.Label).string = player.getName();
                    _this2.myscoreLabel.getComponent(cc.Label).string = items.getScore();

                    if (i == 0) {
                        (function () {

                            var _this = that;
                            cc.loader.loadRes("leave_1", cc.SpriteFrame, function (err, spriteFrame) {

                                _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                            });
                        })();
                    } else if (i == 1) {
                        (function () {

                            var _this = that;
                            cc.loader.loadRes("leave_2", cc.SpriteFrame, function (err, spriteFrame) {

                                _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                            });
                        })();
                    } else if (i == 2) {
                        (function () {

                            var _this = that;
                            cc.loader.loadRes("leave_3", cc.SpriteFrame, function (err, spriteFrame) {

                                _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                            });
                        })();
                    } else {
                        (function () {

                            var _this = that;
                            that.myrankLabel.node.active = true;
                            that.myrankLabel.getComponent(cc.Label).string = i + 1;
                            cc.loader.loadRes("排名底框", cc.SpriteFrame, function (err, spriteFrame) {

                                _this.mysignSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                            });
                        })();
                    }
                }
            }
        });
    },


    closeClick: function closeClick() {

        var changebig = cc.scaleTo(0.02, 1.2);

        var finish = cc.callFunc(function () {

            var that = this;
            var changesmail = cc.scaleTo(0.08, 1.0);

            var smaillfinish = cc.callFunc(function () {

                that.ListAllScrollView.active = false;
            });

            var seq2 = cc.sequence(changesmail, smaillfinish);
            this.rankCloseBtn.node.runAction(seq2);
        }, this);

        var seq = cc.sequence(changebig, finish);

        this.rankCloseBtn.node.runAction(seq);
    },

    start: function start() {},


    worldListClick: function worldListClick() {},

    friendListClick: function friendListClick() {

        this.ListAllScrollView.active = false;
        this.RankingAllView.active = true;
        this.wordScrolView.getComponent("ListScrollView").init();
    }

    // update (dt) {},
});

cc._RF.pop();